package com.muyu.cloud.commodity.domain.model;

import com.muyu.cloud.commodity.domain.req.ProductUpdateReq;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author <a href="mailto:602048165@qq.com">60204</a>
 * @version 1.0
 * @description:
 * @date 2025/9/16 10:52
 */
@Data
public class ProductUpdateModel {
    private Long id;
    private String productName;
    private String productPic;
    private String description;
    private BigDecimal marketPrice;
    private Long categoryId;
    private Long brandId;
    private Integer status;
    private List<ProductSkuUpdateModel> skuList;

    public static ProductUpdateModel buildModel(ProductUpdateReq req) {
        ProductUpdateModel model = new ProductUpdateModel();
        model.setId(req.getId());
        model.setProductName(req.getProductName());
        model.setProductPic(req.getProductPic());
        model.setDescription(req.getDescription());
        model.setMarketPrice(req.getMarketPrice());
        model.setCategoryId(req.getCategoryId());
        model.setBrandId(req.getBrandId());
        model.setStatus(req.getStatus());

        // 转换SKU列表
        List<ProductSkuUpdateModel> skuModels = req.getSkuList().stream()
                .map(ProductSkuUpdateModel::buildModel)
                .toList();
        model.setSkuList(skuModels);

        return model;
    }
}
